﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GrewalCRM.BLL;
using GrewalCRM.Entities;
using GrewalCRM.Entities.Common;


public partial class Reports : System.Web.UI.Page
{
  #region Events
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      populateReportType();
      mvReports.SetActiveView(vwDefaultView);
    }

    ucscCallSC.CallSearch += new UC_SearchCritetia.CallSearchHandler(ucscCallSC_CallSearch);
    ucscCallSC.GetMonthlyCashTransactionReport += new UC_SearchCritetia.GetInstallationSummaryCashTransationReportMonthlyHandler(ucscCallSC_GetMonthlyCashTransactionReport);
  }
  void ucscCallSC_GetMonthlyCashTransactionReport(List<ReportInstallationSummary> rptCashTransaction)
  {
    gvCashReport.DataSource = rptCashTransaction;
    gvCashReport.DataBind();
    Cache["DLR_INSTL_SMRY"] = rptCashTransaction;
    btnPrint.Visible = true;
  }
  void ucscCallSC_CallSearch(List<CallLog> Calls)
  {
    gvDealerReport.DataSource = Calls;
    gvDealerReport.DataBind();
    Cache["DLR_INSTL_DTLS"] = Calls;
  }
  protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
  {
    ReportType reportType = (ReportType)Enum.Parse(typeof(ReportType), ddlReportType.SelectedItem.Text);
    switch (reportType)
    {
      case ReportType.DealerReport:
        mvReports.SetActiveView(vwDealerReport);
        break;
    }
  }  
  protected void gvDealerReport_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
    gvDealerReport.PageIndex = e.NewPageIndex;
    bindGrid();
  }
  protected void gvCashReport_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      Label lblStatusName = e.Row.FindControl("lblStatusName") as Label;

      if (lblStatusName != null && lblStatusName.Text.ToUpper().Trim() == "TOTAL")
      {
        lblStatusName.Font.Bold = e.Row.Font.Bold = true;
      }
    }
  }
  #endregion

  #region Methods
  private void bindGrid()
  {
    ucscCallSC.btnSearch_Click(new object(), new EventArgs());
  }
  private void populateReportType()
  {
    ddlReportType.DataSource = Enum.GetNames(typeof(ReportType));
    ddlReportType.DataBind();
    CommonUtil.AddDefaultItemToDDL(ddlReportType, "Report Type");
  } 
  #endregion

  protected string SiteDomainName
  {
    get { return (this.Page.Master as ImasterCRM).SiteDomainName; }
  }
}